from abc import ABC, abstractmethod

# 抽象产品类 - 电脑
class Computer(ABC):
    @abstractmethod
    def launch(self):
        pass

# 具体产品类 - MacBook
class MacBook(Computer):
    def launch(self):
        return "MacBook 启动中..."

# 具体产品类 - MiBook
class MiBook(Computer):
    def launch(self):
        return "MiBook 启动中..."

# 抽象产品类 - 手机
class Phone(ABC):
    @abstractmethod
    def launch(self):
        pass

# 具体产品类 - iPhone
class iPhone(Phone):
    def launch(self):
        return "iPhone 启动中..."

# 具体产品类 - MiPhone
class MiPhone(Phone):
    def launch(self):
        return "MiPhone 启动中..."

# 抽象工厂
class AbstractFactory(ABC):
    @abstractmethod
    def phone(self) -> Phone:
        pass
    
    @abstractmethod
    def computer(self) -> Computer:
        pass

# 具体工厂 - 苹果工厂
class AppleFactory(AbstractFactory):
    def phone(self) -> Phone:
        return iPhone()
    
    def computer(self) -> Computer:
        return MacBook()

# 具体工厂 - 小米工厂
class MiFactory(AbstractFactory):
    def phone(self) -> Phone:
        return MiPhone()
    
    def computer(self) -> Computer:
        return MiBook()

# 客户端代码
def test_factory(factory: AbstractFactory):
    phone = factory.phone()
    computer = factory.computer()
    
    print(phone.launch())
    print(computer.launch())

# 使用示例
def main():
    print("使用苹果工厂:")
    apple_factory = AppleFactory()
    test_factory(apple_factory)
    
    print("\n使用小米工厂:")
    mi_factory = MiFactory()
    test_factory(mi_factory)

if __name__ == "__main__":
    main()


# 运行结果

# 使用苹果工厂:
# iPhone 启动中...
# MacBook 启动中...

# 使用小米工厂:
# MiPhone 启动中...
# MiBook 启动中...